package com.jiegui.pay.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import javax.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.jiegui.common.annotation.Log;
import com.jiegui.common.core.controller.BaseController;
import com.jiegui.common.core.domain.AjaxResult;
import com.jiegui.common.enums.BusinessType;
import com.jiegui.pay.domain.InterfaceRequest;
import com.jiegui.pay.service.InterfaceRequestService;
import com.jiegui.common.utils.poi.ExcelUtil;
import com.jiegui.common.core.page.TableDataInfo;

/**
 * 接口请求Controller
 * 
 * @author wuqicheng
 * @date 2021-12-10
 */
@RestController
@RequestMapping("/pay/interfaceRequest")
public class InterfaceRequestController extends BaseController
{
    @Resource
    private InterfaceRequestService interfaceRequestService;

    /**
     * 查询接口请求列表
     */
    @PreAuthorize("@ss.hasPermi('pay:interfaceRequest:list')")
    @GetMapping("/list")
    public TableDataInfo list(InterfaceRequest interfaceRequest)
    {
        startPage();
        List<InterfaceRequest> list = interfaceRequestService.selectInterfaceRequestList(interfaceRequest);
        return getDataTable(list);
    }

    /**
     * 导出接口请求列表
     */
    @PreAuthorize("@ss.hasPermi('pay:interfaceRequest:export')")
    @Log(title = "接口请求", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(InterfaceRequest interfaceRequest)
    {
        List<InterfaceRequest> list = interfaceRequestService.selectInterfaceRequestList(interfaceRequest);
        ExcelUtil<InterfaceRequest> util = new ExcelUtil<InterfaceRequest>(InterfaceRequest.class);
        return util.exportExcel(list, "接口请求数据");
    }

    /**
     * 获取接口请求详细信息
     */
    @PreAuthorize("@ss.hasPermi('pay:interfaceRequest:query')")
    @GetMapping(value = "/{flowId}")
    public AjaxResult getInfo(@PathVariable("flowId") String flowId)
    {
        return AjaxResult.success(interfaceRequestService.selectInterfaceRequestByFlowId(flowId));
    }

    /**
     * 新增接口请求
     */
    @PreAuthorize("@ss.hasPermi('pay:interfaceRequest:add')")
    @Log(title = "接口请求", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody InterfaceRequest interfaceRequest)
    {
        return toAjax(interfaceRequestService.insertInterfaceRequest(interfaceRequest));
    }

    /**
     * 修改接口请求
     */
    @PreAuthorize("@ss.hasPermi('pay:interfaceRequest:edit')")
    @Log(title = "接口请求", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody InterfaceRequest interfaceRequest)
    {
        return toAjax(interfaceRequestService.updateInterfaceRequest(interfaceRequest));
    }

    /**
     * 删除接口请求
     */
    @PreAuthorize("@ss.hasPermi('pay:interfaceRequest:remove')")
    @Log(title = "接口请求", businessType = BusinessType.DELETE)
	@DeleteMapping("/{flowIds}")
    public AjaxResult remove(@PathVariable String[] flowIds)
    {
        return toAjax(interfaceRequestService.deleteInterfaceRequestByFlowIds(flowIds));
    }
}
